home *** CD-ROM | disk | FTP | other *** search
/ Programming Microsoft Visual Basic .NET / Programming Microsoft Visual Basic .NET (Microsoft Press)(X08-78517)(2002).bin / setup / vbnet / 24 aspnet applications / aspnetapplications / outputcachingform.aspx.vb < prev    next >
Encoding:
Text File  |  2002-03-18  |  2.0 KB  |  54 lines

  1. Public Class OutputCachingForm
  2.     Inherits System.Web.UI.Page
  3.  
  4.     Protected WithEvents btnRefresh As System.Web.UI.WebControls.Button
  5.     Protected WithEvents txtValue As System.Web.UI.WebControls.TextBox
  6.     Protected WithEvents lblTime As System.Web.UI.WebControls.Label
  7.  
  8. #Region " Web Form Designer Generated Code "
  9.  
  10.     'This call is required by the Web Form Designer.
  11.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  12.  
  13.     End Sub
  14.  
  15.     Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
  16.         'CODEGEN: This method call is required by the Web Form Designer
  17.         'Do not modify it using the code editor.
  18.         InitializeComponent()
  19.     End Sub
  20.  
  21. #End Region
  22.  
  23.     ' Set the following constant to True to override @OutputCache settings
  24.     ' with settings enforced through code
  25. #Const USE_RESPONSECACHE_OBJECT = False
  26.  
  27.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  28.  
  29. #If USE_RESPONSECACHE_OBJECT Then
  30.         Response.Cache.SetCacheability(HttpCacheability.Server)
  31.         Response.Cache.SetExpires(Now.AddSeconds(1))
  32.  
  33.         ' these statements implement validate callback.
  34.         Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches)
  35.         Response.Cache.AddValidationCallback(AddressOf ValidateCache, Nothing)
  36. #End If
  37.  
  38.         ' the job of this page is just to append the current time to the 
  39.         ' contents of the lblTime Label control
  40.         lblTime.Text &= "Current time is " & Date.Now.ToLongTimeString & "<br>"
  41.     End Sub
  42.  
  43.     ' this event fires when the cache is invalidated
  44.  
  45.     Public Sub ValidateCache(ByVal context As HttpContext, ByVal data As Object, ByRef status As HttpValidationStatus)
  46.         If context.Request.QueryString("Refresh") <> "" Then
  47.             status = HttpValidationStatus.Invalid
  48.         Else
  49.             status = HttpValidationStatus.Valid
  50.         End If
  51.     End Sub
  52.  
  53. End Class
  54.